﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Example05.aspx.cs" Inherits="Chapter30.Example05" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代码清单 30-5 使用 addEventListener 和 removeEventListener 方法</title>
    <meta name="author" content="Adam Freeman" />
    <meta name="description" content="A simple example" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
    <style title="cor styles">
        p {
            background: gray;
            color: white;
            padding: 10px;
            margin: 5px;
            border: thin solid black;
        }
    </style>
</head>
<body>
    <p>
        There are lots of different kinds of fruit - there are you over 500 varieties 
        of banana alone. By the time we add the countless 
        types of apples, oranges, and other well-known fruit, we are 
        faced with thousands of choices.
    </p>
    <p id="block2">
        On of the most interesting aspects of fruit is the variety available in
        each country. I live near London, in an area which is known for
        its apples.
    </p>
    <button id="pressme">Press Me</button>
    <script>
        var pElems = document.getElementsByTagName("p");
        for (var i = 0; i < pElems.length; i++) {
            pElems[i].addEventListener("mouseover", handleMouseOver);
            pElems[i].addEventListener("mouseout", handleMouseOut);
        }

        document.getElementById("pressme").onclick = function () {
            document.getElementById("block2").removeEventListener("mouseout", handleMouseOut);
        }

        function handleMouseOver(e) {
            e.target.style.background = 'white';
            e.target.style.color = 'black';
        }

        function handleMouseOut(e) {
            e.target.style.removeProperty('color');
            e.target.style.removeProperty('background');
        }
    </script>
</body>
</html>
